/////////////////////////////////////////////////////////////////////////////
// Original code from libhdfs3. Copyright (c) 2013 - 2014, Pivotal Inc.
// All rights reserved. Author: Zhanwei Wang
/////////////////////////////////////////////////////////////////////////////
//  Modifications by Kumo Inc.
// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//



#pragma once


#include <kmhdfs/client/permission.h>
#include <kmhdfs/client/ec_policy.h>
#include <memory>

#include <string>

namespace Hdfs {
    class FileStatus {
    public:
        FileStatus() : isdir(false), atime(0), blocksize(0), length(0), mtime(0), permission(0644),
                       replications(0), isStriped(false), ecPolicy(nullptr), fileId(0) {
        }

        int64_t getAccessTime() const {
            return atime;
        }

        void setAccessTime(int64_t accessTime) {
            atime = accessTime;
        }

        short getReplication() const {
            return replications;
        }

        void setReplication(short blockReplication) {
            replications = blockReplication;
        }

        int64_t getBlockSize() const {
            return blocksize;
        }

        void setBlocksize(int64_t blocksize) {
            this->blocksize = blocksize;
        }

        const char *getGroup() const {
            return group.c_str();
        }

        void setGroup(const char *group) {
            this->group = group;
        }

        /**
         * Is this a directory?
         * @return true if this is a directory
         */
        bool isDirectory() const {
            return isdir;
        }

        void setIsdir(bool isdir) {
            this->isdir = isdir;
        }

        int64_t getLength() const {
            return length;
        }

        void setLength(int64_t length) {
            this->length = length;
        }

        int64_t getModificationTime() const {
            return mtime;
        }

        void setModificationTime(int64_t modificationTime) {
            mtime = modificationTime;
        }

        const char *getOwner() const {
            return owner.c_str();
        }

        void setOwner(const char *owner) {
            this->owner = owner;
        }

        const char *getPath() const {
            return path.c_str();
        }

        void setPath(const char *path) {
            this->path = path;
        }

        const Permission &getPermission() const {
            return permission;
        }

        void setPermission(const Permission &permission) {
            this->permission = permission;
        }

        const char *getSymlink() const {
            return symlink.c_str();
        }

        void setSymlink(const char *symlink) {
            this->symlink = symlink;
        }

        /**
         * Is this a file?
         * @return true if this is a file
         */
        bool isFile() {
            return !isdir && !isSymlink();
        }

        /**
         * Is this a symbolic link?
         * @return true if this is a symbolic link
         */
        bool isSymlink() {
            return !symlink.empty();
        }

        std::shared_ptr<Internal::ECPolicy> getEcPolicy() const {
            return ecPolicy;
        }

        void setEcPolicy(std::shared_ptr<Internal::ECPolicy> policy) {
            ecPolicy = policy;
        }

        int64_t getFileId() const {
            return fileId;
        }

        void setFileId(int64_t id) {
            fileId = id;
        }

    private:
        bool isdir;
        int64_t atime;
        int64_t blocksize;
        int64_t length;
        int64_t mtime;
        Permission permission;
        short replications;
        std::string group;
        std::string owner;
        std::string path;
        std::string symlink;
        bool isStriped;
        std::shared_ptr<Internal::ECPolicy> ecPolicy;
        int64_t fileId;
    };
}
